/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Entities;

import JDBC.ConnectionPool;
import JDBC.ConnectionPoolException;
import JDBC.Operazioni;
import Logger.MyLogger;
import com.mysql.jdbc.Connection;
import com.mysql.jdbc.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author marcy
 */
public class Pdf {
    
    //Campi entità
    private String url;
    private Timestamp timestamp;
    private int Id_medico;
    
    //Oggetti per lavorare con il database
    private ConnectionPool pool;
    private Connection conn;


    
    public String GetLastPdfUrl (){
        MyLogger.getLogger().debug("Richiesta url pdf");
     url = "";
        try {
            pool = ConnectionPool.getConnetionPool();
            conn = pool.getConnection();
        } catch (ConnectionPoolException ex) {
            Logger.getLogger(Pdf.class.getName()).log(Level.SEVERE, null, ex);
        }
    ResultSet set = Operazioni.execute_query("SELECT P1.Url "
            + " FROM Pdf P1 "
            + " WHERE P1.Timestamp = ("
            + " SELECT max(Timestamp) "
            + " FROM Pdf )", conn);
        try {
            while(set.next()){
                url = set.getString("Url");
            }
        } catch (SQLException ex) {
            Logger.getLogger(Pdf.class.getName()).log(Level.SEVERE, null, ex);
        }
        try {
            set.close();
        } catch (SQLException ex) {
            Logger.getLogger(Pdf.class.getName()).log(Level.SEVERE, null, ex);
        }
    pool.relaseConnection(conn);
    conn= null;
    pool = null;
    System.gc();
    
    return url;
    }
}
